package com.lb.thread;

/**
 * @ClassName AwakenDemo
 * @Author hp
 * @Date 2021/12/23 19:55
 * @Version 1.0
 **/
public class AwakenDemo {
    public static void main(String[] args) {

        Object lock = new Object();

        new Thread(() -> {
            System.out.println("告诉老板要什么东西...");
            //进入等待
            synchronized(lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("拿到东西开始吃...");
        },"顾客线程").start();

        new Thread(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("老板做好了,交给顾客...");
            //通知顾客
            synchronized (lock){
                lock.notify();
            }
        },"老板线程").start();
    }
}
